package com.dongdongshop.controller;


import com.alibaba.fastjson.JSONObject;
import com.dongdongshop.data.Result;
import com.dongdongshop.page.PageParms;
import com.dongdongshop.page.PageResult;
import com.dongdongshop.service.TypeTemplateService;
import com.dongdongshop.vo.TypeTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("typet")
public class TypeTemplateController {
    @Autowired
    private TypeTemplateService tts;

    @PostMapping("selectAll")
    public Result selectAll(@RequestBody PageParms<TypeTemplateVO> parms){
        PageResult<TypeTemplateVO> page = tts.selectAll(parms);
        return Result.OK().setData(page);
    }

    @PostMapping("delete")
    public Result delete(Long[] ids){
        tts.delete(ids);
        return Result.OK();
    }

    @PostMapping("add")
    public Result add (@RequestBody TypeTemplateVO vo){
        tts.add(vo);
        return Result.OK();
    }

    @PostMapping("toUpdate")
    public Result toUpdate(Long id){
        TypeTemplateVO typeTemplateVO = tts.toUpdate(id);
        return Result.OK().setData(typeTemplateVO);
    }

    @PostMapping("update")
    public Result update(@RequestBody TypeTemplateVO vo){
        tts.update(vo);
        return Result.OK();
    }

    @PostMapping("getByItemCatId")
    public Result getByItemCatId(Long itemCatId){
        TypeTemplateVO typeTemplateVO = tts.getByItemCatId(itemCatId);
        return Result.OK().setData(typeTemplateVO);
    }

}
